import 'package:number_spark_flutter/style/ns_style.dart';
import 'package:number_spark_flutter/widgets/brick/ns_brick.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';


class NSBottomActionSheet {
  static show(BuildContext context, List data, {String title = '标题', callBack(int)?}) {
    showModalBottomSheet(
        context: context,
        builder: (BuildContext context) {
          return SafeArea(
            child: Container(
              color: const Color.fromRGBO(255, 255, 255, 0.3),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: <Widget>[
                  //为了防止控件溢出
                  Flexible(
                      child: Container(
                    decoration: const BoxDecoration(
                        color: Colors.white, borderRadius: BorderRadius.only(topLeft: Radius.circular(14), topRight: Radius.circular(14))),
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      children: <Widget>[
//                            new Container(
//                              height: 40,
//                              alignment: Alignment.center,
//                              child: new Text(
//                                title,
//                                textAlign: TextAlign.center,
//                              ),
//                            ),
                        Flexible(
                            child: ListView.builder(
                          shrinkWrap: true,
                          itemCount: data.length,
                          itemBuilder: (context, index) {
                            return Column(
                              children: <Widget>[
                                ListTile(
                                    onTap: () {
                                      Navigator.pop(context);
                                      if (callBack != null) {
                                        callBack!(index);
                                      }
                                    },
                                    title: Text(data[index], textAlign: TextAlign.center, style: TextStyle(fontSize: 16, color: kAppTextColor))),
                                index == data.length - 1
                                    ? Container()
                                    : const Divider(
                                        height: 1,
                                        color: Color(0xFFF0F0F0),
                                      ),
                              ],
                            );
                          },
                        )),
                      ],
                    ),
                  )),
                  const Divider(
                    height: 9,
                    color: Color(0xFFF0F0F0),
                  ),
                  GestureDetector(
                    child: Container(
                      height: 54,
                      width: double.infinity,
                      alignment: Alignment.center,
                      decoration: const BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.all(Radius.circular(0)),
                      ),
                      child: Text('Cancel', textAlign: TextAlign.center, style: TextStyle(fontSize: 16, color: kAppTextColor)),
                    ),
                    onTap: () {
                      //点击取消 弹层消失
                      Navigator.pop(context);
                    },
                  )
                ],
              ),
            ),
          );
        });
  }

  static showDelete(BuildContext context, List data, {String title = '标题', callBack(int)?}) {
    showModalBottomSheet(
        backgroundColor: Colors.transparent,
        context: context,
        builder: (BuildContext context) {
          return SafeArea(
            child: Container(
              color: Colors.transparent,
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: <Widget>[
                  //为了防止控件溢出
                  Flexible(
                      child: Column(
                    mainAxisSize: MainAxisSize.min,
                    children: <Widget>[
                      Flexible(
                          child: ListView.builder(
                        shrinkWrap: true,
                        itemCount: data.length,
                        itemBuilder: (context, index) {
                          return Column(
                            children: <Widget>[
                              NSContainer(
                                margin: EdgeInsets.only(left: 25.w, right: 25.w, top: 7.w),
                                height: 44.w,
                                width: double.infinity,
                                alignment: Alignment.center,
                                color: Colors.white,
                                radius: 12.w,
                                child: Text(data[index],
                                    textAlign: TextAlign.center,
                                    style: TextStyle(fontSize: 14.sp, color: kAppColor('#FF5140'), fontWeight: FontWeight.w500)),
                                onTap: () {
                                  Navigator.pop(context);
                                  if (callBack != null) {
                                    callBack(index);
                                  }
                                },
                              ),
                            ],
                          );
                        },
                      )),
                    ],
                  )),
                  SizedBox(
                    height: 7.w,
                  ),
                  GestureDetector(
                    child: NSContainer(
                      margin: EdgeInsets.only(left: 25.w, right: 25.w, bottom: 25.w),
                      height: 44.w,
                      width: double.infinity,
                      alignment: Alignment.center,
                      color: Colors.white,
                      radius: 12.w,
                      child: Text('取消',
                          textAlign: TextAlign.center, style: TextStyle(fontSize: 14.sp, color: kAppColor('#333333'), fontWeight: FontWeight.w500)),
                    ),
                    onTap: () {
                      //点击取消 弹层消失
                      Navigator.pop(context);
                    },
                  )
                ],
              ),
            ),
          );
        });
  }
}
